﻿CREATE TABLE [dbo].[DBOrder] (
    [ID]                UNIQUEIDENTIFIER DEFAULT (newid()) NOT NULL,
    [RequestedQuantity] INT              NOT NULL,
    [RequestedPrice]    FLOAT            NOT NULL,
    [Side]              CHAR (4)         NOT NULL,
    [Style]             VARCHAR (36)     NOT NULL,
    [TimeInForce]       CHAR (30)         NOT NULL,
    [CreationDate]      DATETIME         NOT NULL,
    [InstrumentID]      UNIQUEIDENTIFIER NULL,
    [StrategyID]        UNIQUEIDENTIFIER NULL,
    PRIMARY KEY CLUSTERED ([ID] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF),
    CHECK ([RequestedQuantity]>(0)),
    CHECK ([RequestedPrice]>(0)),
    CHECK ([Side]='Sell' OR [Side]='Buy'),
    CHECK ([TimeInForce]='Day' OR [TimeInForce]='GoodTillCancel' OR [TimeInForce]='ImmediateOrCancel' OR [TimeInForce]='FillOrKill' OR [TimeInForce]='GoodTillDate' OR [TimeInForce]='MarketOnOpen' OR [TimeInForce]='Undefined'),
    FOREIGN KEY ([InstrumentID]) REFERENCES [dbo].[DBInstruments] ([ID]) ON DELETE CASCADE ON UPDATE NO ACTION,
    FOREIGN KEY ([StrategyID]) REFERENCES [dbo].[DBStrategies] ([ID]) ON DELETE CASCADE ON UPDATE NO ACTION 
);